home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
gui
/
gtlayout.lha
/
Source
/
LTP_LevelClass.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-09
|
29KB
|
1,329 lines
/*
** GadTools layout toolkit
**
** Copyright © 1993-1998 by Olaf `Olsen' Barthel
** Freely distributable.
**
** :ts=4
*/
#ifndef _GTLAYOUT_GLOBAL_H
#include "gtlayout_global.h"
#endif
/*****************************************************************************/
#include <graphics/gfxmacros.h>
#include <clib/alib_protos.h> /* For Coerce/Do/DoSuperMethod */
#include <stdarg.h>
/*****************************************************************************/
#include "Assert.h"
#ifdef DO_LEVEL_KIND /* Support code */
/*****************************************************************************/
#define FAILED (0)
/*****************************************************************************/
STATIC VOID
SliderCleanup(struct SliderClassData *sd)
{
LONG i;
WaitBlit();
for(i = 0 ; i < sd->ThumbBitMap.Depth ; i++)
{
if(sd->ThumbBitMap.Planes[i] != NULL)
{
FreeRaster(sd->ThumbBitMap.Planes[i],sd->ThumbWidth * 2,sd->ThumbHeight);
sd->ThumbBitMap.Planes[i] = NULL;
}
}
}
/****************************************************************************/
#define SCALE_UP(a) ((a) * dri->dri_Resolution.Y)/dri->dri_Resolution.X
#define SCALE_DOWN(a) ((a) * dri->dri_Resolution.X)/dri->dri_Resolution.Y
/****************************************************************************/
LONG
LTP_QuerySliderSize(struct DrawInfo *dri,WORD Reference,WORD freedom,WORD useTicks)
{
LONG thumbWidth,thumbHeight,separatorSpace,pipSpace,result;
if(Reference == 0)
Reference = dri->dri_Font->tf_YSize;
thumbHeight = (Reference + 1) & ~1;
if(thumbHeight < 8)
thumbHeight = 8;
thumbWidth = (((thumbHeight * 1618) / 1000) + 1) & ~1;
if(thumbWidth < 8)
thumbWidth = 8;
thumbHeight = SCALE_DOWN(thumbHeight);
if(thumbHeight < 8)
thumbHeight = 8;
if(freedom == FREEVERT)
{
separatorSpace = 2;
pipSpace = SCALE_UP(4);
if(useTicks != TICKS_None)
{
result = separatorSpace + pipSpace + separatorSpace + thumbWidth + separatorSpace;
if(useTicks == TICKS_Both)
result += pipSpace + separatorSpace;
}
else
{
result = separatorSpace + thumbWidth + separatorSpace;
}
}
else
{
separatorSpace = 2;
pipSpace = SCALE_DOWN(4);
if(useTicks != TICKS_None)
{
result = separatorSpace + pipSpace + separatorSpace + thumbHeight + separatorSpace;
if(useTicks == TICKS_Both)
result += pipSpace + separatorSpace;
}
else
{
result = separatorSpace + thumbHeight + separatorSpace;
}
}
return(result);
}
STATIC BOOL
SliderSetup(struct SliderClassData *sd,WORD Reference,LONG Dimension)
{
struct DrawInfo *dri = sd->DrawInfo;
BOOL IsVertical = sd->IsVertical;
BOOL GotPlanes;
LONG i;
if(Reference == 0)
Reference = dri->dri_Font->tf_YSize;
sd->ThumbHeight = (Reference + 1) & ~1;
if(sd->ThumbHeight < 8)
sd->ThumbHeight = 8;
sd->ThumbWidth = (((sd->ThumbHeight * 1618) / 1000) + 1) & ~1;
if(sd->ThumbWidth < 8)
sd->ThumbWidth = 8;
sd->ThumbHeight = SCALE_DOWN(sd->ThumbHeight);
if(sd->ThumbHeight < 8)
sd->ThumbHeight = 8;
InitBitMap(&sd->ThumbBitMap,min(8,dri->dri_Depth),sd->ThumbWidth * 2,sd->ThumbHeight);
GotPlanes = TRUE;
for(i = 0 ; i < sd->ThumbBitMap.Depth ; i++)
{
sd->ThumbBitMap.Planes[i] = AllocRaster(sd->ThumbWidth * 2,sd->ThumbHeight);
if(sd->ThumbBitMap.Planes[i] == NULL)
{
GotPlanes = FALSE;
break;
}
}
if(GotPlanes)
{
struct RastPort rp;
UWORD *pens = dri->dri_Pens;
LONG width,height;
width = height = Dimension;
InitRastPort(&rp);
rp.BitMap = &sd->ThumbBitMap;
SetRast(&rp,pens[BACKGROUNDPEN]);
SetDrMd(&rp,JAM1);
SetAPen(&rp,pens[SHINEPEN]);
if(IsVertical)
{
Move(&rp,0,(sd->ThumbHeight / 2) - 2);
Draw(&rp,0,0);
Draw(&rp,sd->ThumbWidth - 2,0);
Move(&rp,0,sd->ThumbHeight - 2);
Draw(&rp,0,sd->ThumbHeight / 2);
Draw(&rp,sd->ThumbWidth - 2,sd->ThumbHeight / 2);
SetAPen(&rp,pens[SHADOWPEN]);
Move(&rp,1,(sd->ThumbHeight / 2) - 1);
Draw(&rp,sd->ThumbWidth - 1,(sd->ThumbHeight / 2) - 1);
Draw(&rp,sd->ThumbWidth - 1,1);
Move(&rp,1,sd->ThumbHeight - 1);
Draw(&rp,sd->ThumbWidth - 1,sd->ThumbHeight - 1);
Draw(&rp,sd->ThumbWidth - 1,(sd->ThumbHeight / 2) + 1);
sd->SeparatorSpace = 2;
sd->TickSpace = SCALE_UP(4);
if(sd->UseTicks != TICKS_None)
{
sd->Width = sd->SeparatorSpace + sd->TickSpace + sd->SeparatorSpace + sd->ThumbWidth + sd->SeparatorSpace;
sd->Height = height;
sd->TickTop = sd->SeparatorSpace;
sd->RailTop = sd->SeparatorSpace + sd->TickSpace + sd->SeparatorSpace + (sd->ThumbWidth / 2) - 2;
sd->ThumbTop = sd->SeparatorSpace + sd->TickSpace + sd->SeparatorSpace;
if(sd->UseTicks == TICKS_Both)
sd->Width += sd->TickSpace + sd->SeparatorSpace;
}
else
{
sd->Width = sd->SeparatorSpace + sd->ThumbWidth + sd->SeparatorSpace;
sd->Height = height;
sd->TickTop = sd->SeparatorSpace;
sd->RailTop = sd->SeparatorSpace + (sd->ThumbWidth / 2) - 2;
sd->ThumbTop = sd->SeparatorSpace;
}
sd->ThumbLast = sd->Height - sd->ThumbHeight;
if(sd->ThumbMax == 0)
sd->ThumbLeft = 0;
else
sd->ThumbLeft = (sd->ThumbLast * sd->ThumbPosition) / sd->ThumbMax;
ClipBlit(&rp,0,0,&rp,sd->ThumbWidth,0,sd->ThumbWidth,sd->ThumbHeight,0xC0);
SetAPen(&rp,pens[FILLPEN]);
RectFill(&rp,sd->ThumbWidth + 1,1,sd->ThumbWidth + sd->ThumbWidth - 2,(sd->ThumbHeight / 2) - 2);
RectFill(&rp,sd->ThumbWidth + 1,(sd->ThumbHeight / 2) + 1,sd->ThumbWidth + sd->ThumbWidth - 2,sd->ThumbHeight - 2);
}
else
{
Move(&rp,(sd->ThumbWidth / 2) - 2,0);
Draw(&rp,0,0);
Draw(&rp,0,sd->ThumbHeight - 2);
Move(&rp,sd->ThumbWidth - 2,0);
Draw(&rp,sd->ThumbWidth / 2,0);
Draw(&rp,sd->ThumbWidth / 2,sd->ThumbHeight - 2);
SetAPen(&rp,pens[SHADOWPEN]);
Move(&rp,(sd->ThumbWidth / 2) - 1,1);
Draw(&rp,(sd->ThumbWidth / 2) - 1,sd->ThumbHeight - 1);
Draw(&rp,1,sd->ThumbHeight - 1);
Move(&rp,sd->ThumbWidth - 1,1);
Draw(&rp,sd->ThumbWidth - 1,sd->ThumbHeight - 1);
Draw(&rp,(sd->ThumbWidth / 2) + 1,sd->ThumbHeight - 1);
sd->SeparatorSpace = 2;
sd->TickSpace = SCALE_DOWN(4);
if(sd->UseTicks != TICKS_None)
{
sd->Width = width;
sd->Height = sd->SeparatorSpace + sd->TickSpace + sd->SeparatorSpace + sd->ThumbHeight + sd->SeparatorSpace;
sd->TickTop = sd->SeparatorSpace;
sd->RailTop = sd->SeparatorSpace + sd->TickSpace + sd->SeparatorSpace + (sd->ThumbHeight / 2) - 2;
sd->ThumbTop = sd->SeparatorSpace + sd->TickSpace + sd->SeparatorSpace;
if(sd->UseTicks == TICKS_Both)
sd->Height += sd->TickSpace + sd->SeparatorSpace;
}
else
{
sd->Width = width;
sd->Height = sd->SeparatorSpace + sd->ThumbHeight + sd->SeparatorSpace;
sd->TickTop = sd->SeparatorSpace;
sd->RailTop = sd->SeparatorSpace + (sd->ThumbHeight / 2) - 2;
sd->ThumbTop = sd->SeparatorSpace;
}
sd->ThumbLast = sd->Width - sd->ThumbWidth;
if(sd->ThumbMax == 0)
sd->ThumbLeft = 0;
else
sd->ThumbLeft = (sd->ThumbLast * sd->ThumbPosition) / sd->ThumbMax;
ClipBlit(&rp,0,0,&rp,sd->ThumbWidth,0,sd->ThumbWidth,sd->ThumbHeight,0xC0);
SetAPen(&rp,pens[FILLPEN]);
RectFill(&rp,sd->ThumbWidth + 1,1,sd->ThumbWidth + (sd->ThumbWidth / 2) - 2,sd->ThumbHeight - 2);
RectFill(&rp,sd->ThumbWidth + (sd->ThumbWidth / 2) + 1,1,sd->ThumbWidth + sd->ThumbWidth - 2,sd->ThumbHeight - 2);
}
}
else
{
SliderCleanup(sd);
}
return(GotPlanes);
}
STATIC VOID
DrawTicks(struct RastPort *rp,LONG left,LONG top,UWORD *pens,struct SliderClassData *sd)
{
if(sd->UseTicks != TICKS_None)
{
LONG numTicks,maxTicks;
if(sd->IsVertical)
maxTicks = (sd->Height - sd->ThumbHeight + 4) / 4;
else
maxTicks = (sd->Width - sd->ThumbWidth + 4) / 4;
if(sd->NumTicks > 0)
numTicks = sd->NumTicks;
else
numTicks = sd->ThumbMax + 1;
while(numTicks > maxTicks && numTicks > 1)
numTicks = numTicks / 2;
if(numTicks > 1)
{
LONG x,y,i;
if(sd->IsVertical)
{
for(i = 0 ; i < numTicks ; i++)
{
x = left + sd->TickTop;
y = top + (i * (sd->Height - sd->ThumbHeight)) / (numTicks - 1) + (sd->ThumbHeight / 2) - 1;
SetAPen(rp,pens[SHAD